var app = angular.module('conversionTool', []);

app.controller('registerCtrl', [ '$scope', '$http', function($scope, $http) {

	$scope.gotoLogin = function() {

		location.href = "login";

	}

	$scope.register = function() {

		if ($scope.form.email.$error.required) {
			$scope.msg = "The Email is required!";
			
		}else if($scope.form.email.$error.email){
			$scope.msg = "The email is invalid!";
			
		}else  if($scope.form.company .$error.required){
			$scope.msg = "company is required!";
			
		}
		else if ($scope.form.password.$error.required){
			
			$scope.msg = "password is required!";
		}
		else if($scope.form.passwordConfirm.$error.required)
			{
			
			$scope.msg = "passwordConfirm is required!";
			}
		else if ($scope.password != $scope.passwordConfirm)
			{
			$scope.msg = "passwords do not  match!";
			}
		else if ($scope.form.userName.$error.required)
			
			{
			$scope.msg = "username is required!";
			}
		
		else {

			$http.post('/rest/account/register', {
				"email" : $scope.email,
				"password" : $scope.password,
				"userName" : $scope.userName,
				"company" : $scope.company,
			}).success(function(data) {

				if (data == true) {
					location.href = "/"
				} else {

					$scope.msg = "The email is exisited!";
				}

			}).error(function(data) {

				console.log(data);
			});

		}

	}

} ]);